#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

void solve() {
    ll l, r;
    cin >> l >> r;
    if (l == r) {
        cout << "0" << endl;
        return;
    }
    int maxb = 0;
    for (int i = 63; i >= 0; i--) {
        if (((l >> i) & 1) != ((r >> i) & 1)) {
            maxb=i;
            break;
        }
    }
    cout<<(1ll<<(maxb+1))-1<<endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();

    return 0;
}